//
//  MainViewController.swift
//  Runner
//
//  Created by skj on 2021/5/21.
//

import UIKit
import SnapKit
class MainViewController: BasedViewController {
    override class func loaded() {
        HZTRouter.registerURLPattern(Router_URL_Home) { (routerParamers)->Void in
            AppConfig.shared.rootNav?.popToRootViewController(animated: true);
        }
    }
    var flutterContainer:FBFlutterViewContainer!
    override func viewDidLoad() {
        super.viewDidLoad()
        isPreferHidenNavBar = true
        HZTPathManager.default()?.pathDelegate = self
        configRouter()
        flutterContainer = FBFlutterViewContainer.init()
        flutterContainer?.setName("/tab", uniqueId: nil, params: nil, opaque: false)
        view.addSubview(flutterContainer!.view)
        flutterContainer?.view.snp.makeConstraints({ (make) in
            make.edges.equalTo(UIEdgeInsets.zero)
        })
        addChild(flutterContainer)

    }
    override func didMove(toParent parent: UIViewController?) {
        flutterContainer.didMove(toParent: parent)
        super.didMove(toParent: parent)
    }
}
extension MainViewController {
    func configRouter(){
        HZTPathManager.configScheme(AppScheme, host: AppHost)
        HZTRouter.configScheme(AppScheme, host: AppHost)
        HZTPathManager.configNavStackContainer { () -> UINavigationController? in
            return AppConfig.shared.rootNav
        }
        HZTRouter.configNotFoundHandlerBlock { (url) -> Bool in
            if url == Router_URL_Common_QR {
                HZDeviceInfo.requestAccessPermission(forAlbum: {(bool)->() in
                    guard bool else {
                        return
                    }
                    let storyboard = UIStoryboard(name: "Main", bundle: nil)
                    let toVC = storyboard.instantiateViewController(withIdentifier: "QR")
                    AppConfig.shared.rootNav?.pushViewController(toVC, animated: true)

                })
            } else {
                ////                AppConfig.shared.currentVC?.transitionToWeb(withUrl: url ?? "")

            }
            return true
        }
        HZTPathManager.configAppVersionBlock { () -> String? in
            return "1.0.0"
        }
        HZTPathManager.configSearchPathBlock { (url) -> PathConfigModel? in
            return nil
        }
        HZTPathManager.configUserLoginStatusBlock { () -> Bool in
            return true
        }
    }
}
extension MainViewController:HZTPathManagerDelegate {
    func interceptePathForRun(byReactNative param: NSMutableDictionary!) {
        HZTRouter.openURL(Router_URL_Common_ReactNative, withUserInfo: param)
    }
    func interceptePath(forHandleMoudleWeb param: NSMutableDictionary!) {

    }
    func interceptePathForRun(byCommonWeb param: NSMutableDictionary!) {

    }
    func interceptePath(forUserNeedLogin param: NSMutableDictionary!) {

    }

    func interceptePath(forVersionLow param: NSMutableDictionary!) {

    }

    func interceptePath(forDelete param: NSMutableDictionary!) {

    }

    func interceptePath(forNotFound param: NSMutableDictionary!) {

    }

}
